package classes.singleton;

/**
 * 懒汉式单例设计模式
 */
public class Singleton2 {
    private static Singleton2 singleton = null;

    private Singleton2() {

    }

    public static Singleton2 getSingleton() {
        if(singleton == null){
            synchronized(bank.Bank.class){ //为了线程安全，且效率较高
                if (singleton == null) {  //保证只实例化一次
                    singleton = new Singleton2();
                }
            }
        }
        return singleton;
    }
}
